<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use DB;


class Checkgroup extends Model
{
    protected $table = 'checkgroup';
    public $timestamps = false;

    public function getGroup()
    {
        return $this->belongsTo('Models\Company', 'category');
    }

    //
    public function getEntry($ids)
    {
        // $groupInfo = Checkgroup::find($groupId);
        $checkentry = DB::select("select id,entry from checkentry where id in ( {$ids} ) order by id asc ");
        return $checkentry;
    }

    public static function getCheckgroup($categoryId, $fire, $nofire)
    {
        //获取类型
        $getCheckcategory = self::where('categoryId', $categoryId)->get()->toArray();
        $data = $xfaq = $scaq = [];
        if($categoryId!=12){  //企业隐患排查跟九小场所隐患排查
            $data = [
                ['title' => '消防安全','iscomplete'=>$fire,'firetype'=>1,
                    'child'=>           [['groupId' => Checkgroup::where(['categoryId'=>$categoryId,'status'=>1,'type'=>1])->first()->id,
                        'status' => 0,
                        'type' => 1,
                        'title'=>'基础档案'],
                        ['groupId' => Checkgroup::where(['categoryId'=>$categoryId,'status'=>2,'type'=>1])->first()->id,
                            'status' => 0,
                            'type' => 1,
                            'title'=>'作业现场'
                        ]],
                ],
                ['title' => '生产安全','iscomplete'=>$nofire,'firetype'=>2,
                    'child'=>           [['groupId' => Checkgroup::where(['categoryId'=>$categoryId,'status'=>1,'type'=>2])->first()->id,
                        'status' => 0,
                        'type' => 2,
                        'title'=>'基础档案'],
                        ['groupId' => Checkgroup::where(['categoryId'=>$categoryId,'status'=>2,'type'=>2])->first()->id,
                            'status' => 0,
                            'type' => 2,
                            'title'=>'作业现场'
                        ]],
                ],
            ];
        }else{  //居家安全隐患排查
            foreach ($getCheckcategory as $key => $val) {
                if($val['name']){
                    $data[$key] = [
                        'title' => $val['name'],
                        'iscomplete' => 0,
                        'firetype' => 5,
                        'groupId' => $val['id']
                    ];
                }
            }
        }
        return $data;
    }
}
